<?php

namespace App\Http\Requests\Admin\Config;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ServerRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
//    public function rules()
//    {
//        $where = [
//            'game_id' => request()->get('game_id'),
//            'channel_id' => request()->get('channel_id'),
//            'server_id' => request()->get('server_id'),
//        ];
//
//        if (request()->method() == 'POST') {
//            return [
//                'game_id' => 'required',
//                'channel_id' => 'required',
//                'server_id' => ['required',
//                    Rule::unique('mongodb.snapshot_channel')
//                        ->where(function ($query) use ($where) {
//                            return $query->where($where);
//                        })
//                ],
//                'server_name' => 'required',
//            ];
//        } elseif (request()->method() == 'PATCH') {
//            return [
//                'game_id' => 'required',
//                'channel_id' => 'required',
//                'server_id' => [
//                    'required',
//                    Rule::unique('mongodb.snapshot_channel')
//                        ->where(function ($query) use ($where) {
//                            return $query->where($where)->where('_id', '!=', request()->route('server'));
//                        })
//                ],
//                'server_name' => 'required',
//            ];
//        }
//    }
    public function rules()
    {
        if (request()->method() == 'PATCH') {
            return [
                'server_name' => 'required',
            ];
        }
    }

    /**
     * 提示信息s
     * @return array
     */
    public function messages()
    {
        return [
            'server_name.required' => '服务器名称不能为空',
        ];
    }
}
